﻿

/*加入收藏夹LTH(2011-5-10)*/
function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

function reload() {
    window.location.reload();
}

function SetMaxWidth(InnerDomID, width) {
    $(document).ready(function () {
        $("#" + InnerDomID + " *").each(function () {
            if ($(this).width() > width)
                $(this).width(width);
        });
    });
}


/*设为首页LTH(2011-5-10)*/
function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}

function copyUrl(copy) {

    if (window.clipboardData) {
        window.clipboardData.setData("Text", copy);
    }
    else if (window.netscape) {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext = copy;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip) return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);
    }
    alert("已复制" + copy)
    return false;
}


var expdate = new Date();

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function Cookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function setCookie(name, value, expires, path, domain, secure) {
    expdate.setTime(expdate.getTime() + (expires * 24 * 60 * 60 * 1000));
    document.cookie = name + "=" + escape(value) +
 ((expires) ? "; expires=" + expdate.toGMTString() : "") +
 ((path) ? "; path=" + path : "") +
 ((domain) ? "; domain=" + domain : "") +
 ((secure) ? "; secure" : "");
}

function deleteCookie(name) {
    expdate = new Date();
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
    setCookie(name, "", expdate);
}

function getQuerystring(key) {
    //key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)&?", ["i"]);
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return '';
    else
        return qs[1];
}


/**
*WindowMask 遮罩 开始
*修改时间：2012-08-22 活动号：6396000241  修改人:张恒辉 
*使用：var mask=new WindowMask(); mask.show();
**/
function WindowMask(id) {
    if (id) {
        this.id = id;
        this.jqueryId = "#" + id
    } else {
        this.id = "windowMask"
        this.jqueryId = "#windowMask"
    }
    this.style = {
        "position": "absolute",
        "top": "0px",
        "left": "0px",
        "width": "100%",
        "background-color": "#333333",
        "opacity": " 0.5",
        "filter": "alpha(opacity=50)",
        "z-index": "99",
        "height": "0px"
    }
}
WindowMask.fn = WindowMask.prototype;
WindowMask.fn.init = function () { //初始化
    var style = "";
    if ($(window).height() > $(document).height()) {
        this.style.height = ($(window).height() - 5) + "px";
    } else {
        this.style.height = $(document).height() + "px";
    }
    for (var key in this.style) {
        style += key + ":" + this.style[key] + ";";
    }
    $("body").append("<div id=\"" + this.id + "\" style=\"" + style + "\" ></div>");
    $(window).resize(jQuery.proxy(this.resize, this));
}
WindowMask.fn.setStyle = function (cssJson) { //设置样式
    $(this.jqueryId).css(cssJson);
}
WindowMask.fn.setText = function (msg) { //设置文本
    var msgDIV = "<div style=\"margin-top:" + $(window).height() * 0.45 + "px; width:100%;text-align:center;color:#ffffff;font-weight:bold;\">" + msg + "</div>"
    $(this.jqueryId).html(msgDIV);
}
WindowMask.fn.setHTML = function (html) {  //设置html
    $(this.jqueryId).html(html);
}
WindowMask.fn.show = function (msg) {  //显示
    if ($(this.jqueryId).length == 0) {
        this.init();
    }
    if (msg) this.setText(msg);
    this.setStyle({ "display": "block" });
}
WindowMask.fn.hide = function () {
    this.setStyle({ "display": "none" });
}
WindowMask.fn.resize = function () { //遮罩随窗口改变
    if ($(window).height() > $(document).height()) {
        this.style.height = ($(window).height() - 5) + "px";
    } else {
        this.style.height = $(document).height() + "px";
    }
    this.setStyle({ "height": this.style.height });
}
/**WindowMask 遮罩  修改时间：2012-08-22 活动号：6396000241  修改人:张恒辉  结束**/

// Seesion 过期 ajax 请求处理 
function CheckSessionTimeOut(data) {
    try {
        if (typeof (data) == "string") {
            data = $.parseJSON(data); //转换
        }
        if (data && data["sessionStatus"] && data["sessionStatus"] == "timeout") {
            var host = window.location.protocol + "\\\\" + window.location.host;
            var regex = new RegExp(host, ["i"]);
            var item = regex.exec(data["url"]);
            if (item == null) {
                window.location.href = host + data["url"];
            } else {
                window.location.href = data["url"];
            }

        }
    }
    catch (err) { }
}


